package com.fept.msgcore.msgserver.protocol.frame;

import com.fept.msgcore.msgserver.protocol.model.header.Header;

/**
 * Created by Srma on 2/9/2017.
 */
public class ProtocolMessage {

    /**
     * 封装协议消息
     *
     * @param frame
     * @return
     */
    public static byte[] packing(Frame frame) {
        return frame.pack();
    }

    /**
     * 解封装协议消息
     *
     * @param headerData
     * @param data
     * @return
     * @throws Exception
     */
    public static Frame unpacking(byte[] headerData, byte[] data) {
        Frame frame = new Frame();
        frame.unpack(headerData, data);
        return frame;
    }

    /**
     * 计算除了帧头的数据长度
     *
     * @param header
     * @return
     */
    public static int frameLength(byte[] headerData) {
        Header header = new Header();
        header.unpack(headerData, 0);
        return header.getTotalLength() - Header.getHeaderLength();
    }
}
